﻿#region License

/*
 © 2012 Alex Kazaev
 * FolderDrive project [http://folderdrive.codeplex.com/]
 * Licensed under Ms-PL license [http://www.opensource.org/licenses/MS-PL]
 */

#endregion License

using System;
using System.Windows;
using System.Windows.Forms;
using FolderDrive.ViewModels;

namespace FolderDrive.Controls
{
  /// <summary>
  /// Interaction logic for AddMappingControl.xaml
  /// </summary>
  public partial class AddMappingControl
  {
    public Action<bool> Finished;

    public AddMappingControl()
    {
      InitializeComponent();
    }

    //TODO: get rid of this ugly property
    private AddMappingViewModel ViewModel
    {
      get
      {
        AddMappingViewModel result = null;
        var parentViewModel = DataContext as FolderDriveViewModel;
        if (parentViewModel != null)
        {
          result = parentViewModel.MappingViewModel;
        }
        return result;
      }
    }

    private void OnSelectFolderButtonClick(object sender, RoutedEventArgs e)
    {
      var dlg = new FolderBrowserDialog();
      if (dlg.ShowDialog() == DialogResult.OK)
      {
        ViewModel.SelectedPath = dlg.SelectedPath;
      }
    }

    private void OnCancelButtonClick(object sender, RoutedEventArgs e)
    {
      if (Finished != null)
      {
        Finished(false);
      }
    }

    private void OnOkButtonClick(object sender, RoutedEventArgs e)
    {
      if (Finished != null && ViewModel.CheckDataAndGenerateMappingItem())
      {
        Finished(true);
      }
    }
  }
}